package com.ruoyi.system.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.TaskLog;
import com.ruoyi.system.domain.TaskLogFour;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TaskFour;
import com.ruoyi.system.service.ITaskFourService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/four")
public class TaskFourController extends BaseController
{
    @Autowired
    private ITaskFourService taskFourService;

    /**
     * 查询【任务四】列表
     */
    @PreAuthorize("@ss.hasPermi('system:four:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskFour taskFour)
    {
        startPage();
        List<TaskFour> list = taskFourService.selectTaskFourList(taskFour);
        return getDataTable(list);
    }

    /**
     * 导出【任务四】列表
     */
    @PreAuthorize("@ss.hasPermi('system:four:export')")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskFour taskFour)
    {
        List<TaskFour> list = taskFourService.selectTaskFourList(taskFour);
        ExcelUtil<TaskFour> util = new ExcelUtil<TaskFour>(TaskFour.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:four:query')")
    @GetMapping(value = "/{id}")
    @Log(title = "四号表详情", businessType = BusinessType.DETAIL, tableIndex = 4)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(taskFourService.selectTaskFourById(id));
    }

    /**
     * 新增【任务四】
     */
    @PreAuthorize("@ss.hasPermi('system:four:add')")
    @Log(title = "四号表新增", businessType = BusinessType.INSERT, tableIndex = 4, isAnalysisJson = true)
    @PostMapping
    public AjaxResult add(@RequestBody TaskFour taskFour)
    {

        taskFourService.insertTaskFour(taskFour);

        TaskLogFour taskLogFour = new TaskLogFour();
        taskLogFour.setTaskId(taskFour.getId());

        return AjaxResult.success("200",taskLogFour);
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:four:edit')")
    @Log(title = "四号表修改", businessType = BusinessType.UPDATE,tableIndex = 4)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskFour taskFour)
    {

        taskFourService.updateTaskFour(taskFour);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("id", taskFour.getId());
        return AjaxResult.success("操作成功",map);
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:four:remove')")
    @Log(title = "四号表删除", businessType = BusinessType.DELETE,tableIndex = 4)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        taskFourService.deleteTaskFourByIds(ids);
        String id = Arrays.toString(ids).replace("[", "").replace("]", "");
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("id",  id);
        return AjaxResult.success("操作成功",map);
    }
}
